//    Copyright (C) 2013  <lugocreation@gmail.com>
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
package org.jpgolay.me.persistence;

import java.io.PrintStream;
import java.sql.*;

// Referenced classes of package org.jpgolay.me.persistence:
//            ConnectDB
public class OLD_RequestDB {

    public OLD_RequestDB() {
        type = 0;
        type = 0;
        connexion = ConnectDB.getConnection();
    }

    public OLD_RequestDB(int i) {
        type = 0;
        type = i;
        switch (type) {
            case 0: // '\0'
                connexion = ConnectDB.getConnection();
                break;

            case 1: // '\001'
                connexion = ConnectDB.getNewConnexion();
                break;

            default:
                type = 0;
                connexion = ConnectDB.getConnection();
                break;
        }
    }

    public void open() {
    }

    public ResultSet getTable(String requete) {
        try {
            if (requete.equals("")) {
                System.out.println("Contenu de la requ\352te invalide !");
                jeuResultats = null;
            } else {
                instruction = connexion.createStatement();
                jeuResultats = instruction.executeQuery(requete);
            }
        } catch (SQLException sqlex) {
            System.out.println("Methode getTable() !\n" + sqlex);
            jeuResultats = null;
        }
        return jeuResultats;
    }

    public ResultSet getTableMoveList(String requete) {
        try {
            if (requete.equals("")) {
                System.out.println("Contenu de la requ\352te invalide !");
                jeuResultats = null;
            } else {
                instruction = connexion.createStatement(1005, 1007);
                jeuResultats = instruction.executeQuery(requete);
            }
        } catch (SQLException sqlex) {
            System.out.println("Methode getTableMoveList() !\n" + sqlex);
            jeuResultats = null;
        }
        return jeuResultats;
    }

    public boolean setTable(String requete) {
        boolean resultat;
        try {
            if (requete.equals("")) {
                System.out.println("Contenu de la requ\352te invalide !");
                resultat = false;
            } else {
                instruction = connexion.createStatement();
                int count = instruction.executeUpdate(requete);
                if (count == 0) {
                    resultat = false;
                } else {
                    resultat = true;
                }
            }
        } catch (SQLException sqlex) {
            System.out.println("Methode setTable() !\n" + sqlex);
            resultat = false;
        }
        return resultat;
    }

    public void close() {
        if (type == 1) {
            ConnectDB.closeConnection(connexion);
        }
    }
    private Statement instruction;
    private ResultSet jeuResultats;
    private Connection connexion;
    public static final int COMMON = 0;
    public static final int NEW = 1;
    private int type;
}
